﻿<phone:PhoneApplicationPage 
    x:Class="PressureDiary.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:controls="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls"
    xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls.Primitives;assembly=Microsoft.Phone.Controls.Toolkit"
    xmlns:toolkit1="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
    xmlns:local="clr-namespace:PressureDiary.NumberSelector"
    xmlns:setting="clr-namespace:PressureDiary"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"     
    mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768" 
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait"  Orientation="Portrait"
    shell:SystemTray.IsVisible="True">

    <phone:PhoneApplicationPage.Resources>
        <setting:AppSettings x:Key="appSettings" />
    </phone:PhoneApplicationPage.Resources>

    <!--LayoutRoot is the root grid where all page content is placed-->
    <Grid x:Name="LayoutRoot">
        <!--Pivot Control-->
        <controls:Pivot Title="PRESSURE DIARY" Opacity="1">
            <!--Pivot item one-->
            <controls:PivotItem Header="new measure">
                <Grid>
                    <Grid.Resources>
                        <DataTemplate x:Key="NumberTemplate">
                            <Grid>
                                <TextBlock Text="{Binding}" FontSize="48" FontFamily="{StaticResource PhoneFontFamilySemiBold}" HorizontalAlignment="Center" VerticalAlignment="Center" />
                            </Grid>
                        </DataTemplate>
                    </Grid.Resources>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="30" />
                        <RowDefinition Height="350" />
                        <RowDefinition />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition />
                        <ColumnDefinition />
                        <ColumnDefinition />
                    </Grid.ColumnDefinitions>
                    <TextBlock Text="Systolic" Grid.Row="0" Grid.Column="0" TextAlignment="Center" Style="{StaticResource PhoneTextAccentStyle}" />
                    <toolkit:LoopingSelector Grid.Row="1" Grid.Column="0" x:Name="Max" Margin="12" Width="120" ItemSize="120,120" ItemTemplate="{StaticResource NumberTemplate}" />
                    <TextBlock Text="Diastolic" Grid.Row="0" Grid.Column="1" TextAlignment="Center" Style="{StaticResource PhoneTextAccentStyle}" />
                    <toolkit:LoopingSelector Grid.Row="1" Grid.Column="1" x:Name="Min" Margin="12" Width="120" ItemSize="120,120" ItemTemplate="{StaticResource NumberTemplate}" />
                    <TextBlock Text="Pulse" Grid.Row="0" Grid.Column="2" TextAlignment="Center" Style="{StaticResource PhoneTextAccentStyle}" />
                    <toolkit:LoopingSelector Grid.Row="1" Grid.Column="2" x:Name="HeartBeat" Margin="12" Width="120" ItemSize="120,120" ItemTemplate="{StaticResource NumberTemplate}" />                    
                    <StackPanel Grid.Row="2" Grid.ColumnSpan="3">
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition />
                                <RowDefinition />
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition />
                                <ColumnDefinition />
                            </Grid.ColumnDefinitions>
                            <TextBlock Grid.Row="0" Grid.Column="0" x:Name="txtMeasureDate" Text="Date" />
                            <toolkit1:DatePicker Grid.Row="1" Grid.Column="0" Name="datePickerMeasurementDate" GotFocus="datePickerMeasurementDate_GotFocus" />
                            <TextBlock Grid.Row="0" Grid.Column="1" x:Name="txtMeasureTime" Text="Time" />
                            <toolkit1:TimePicker Grid.Row="1" Grid.Column="1" Name="timePickerMeasurementTime" GotFocus="timePickerMeasurementTime_GotFocus" />
                        </Grid>
                                                
                        <Button x:Name="btnSave" Height="100" Content="Save" Click="btnSave_Click" />
                    </StackPanel>
                </Grid>
            </controls:PivotItem>

            <!--Pivot item two-->
            <controls:PivotItem Header="measurements">
                <!--Triple line list no text wrapping-->
                <!-- Versione 1.2 con aggiunta numero di misurazioni per mese in corso -->
                <!--<Grid x:Name="MeasurementGrid">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="30" />
                        <RowDefinition />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition />
                        <ColumnDefinition />
                        <ColumnDefinition />
                    </Grid.ColumnDefinitions>
                    <TextBlock Text="Systolic" Grid.Row="0" Grid.Column="0" TextAlignment="Center" />
                    <TextBlock Text="Diastolic" Grid.Row="0" Grid.Column="1" TextAlignment="Center" />
                    <TextBlock Text="Pulse" Grid.Row="0" Grid.Column="2" TextAlignment="Center" />
                    <ListBox x:Name="MeasurementListBox" Grid.Row="1" Grid.ColumnSpan="3" Margin="0,10,-12,0" ItemsSource="{Binding Measures}">
                        <ListBox.ItemTemplate>
                            <DataTemplate>
                                <Grid>
                                    <Grid.RowDefinitions>
                                        <RowDefinition />
                                        <RowDefinition Height="30" />
                                        <RowDefinition Height="20" />
                                    </Grid.RowDefinitions>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="160" />
                                        <ColumnDefinition Width="160" />
                                        <ColumnDefinition Width="160" />
                                    </Grid.ColumnDefinitions>
                                    <StackPanel Grid.Row="0" Grid.Column="0" Orientation="Horizontal">
                                        <TextBlock Text="{Binding Systolic}"  TextAlignment="Center" TextWrapping="NoWrap" Margin="12,0,0,0" Style="{StaticResource PhoneTextExtraLargeStyle}"/>
                                        <TextBlock Text="mmHg" Margin="12,0,0,0" />
                                    </StackPanel>
                                    <StackPanel Grid.Row="0" Grid.Column="1" Orientation="Horizontal">
                                        <TextBlock Text="{Binding Diastolic}" TextAlignment="Center" TextWrapping="NoWrap" Margin="12,0,0,0" Style="{StaticResource PhoneTextExtraLargeStyle}"/>
                                        <TextBlock Text="mmHg" Margin="12,0,0,0" />
                                    </StackPanel>
                                    <StackPanel Grid.Row="0" Grid.Column="2" Orientation="Horizontal">
                                        <TextBlock Text="{Binding Pulse}" TextAlignment="Center" TextWrapping="NoWrap" Margin="12,0,0,0" Style="{StaticResource PhoneTextExtraLargeStyle}"/>
                                        <TextBlock Text="/min" Margin="12,0,0,0" />
                                    </StackPanel>
                                    <StackPanel Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="3" Orientation="Horizontal">
                                        <TextBlock Text="Measurement date" />
                                        <TextBlock Text="{Binding Date, StringFormat=d}" TextWrapping="NoWrap" Margin="12,0,0,0" />
                                        <TextBlock Text="{Binding TimeMeasure, StringFormat=t}" TextWrapping="NoWrap" Margin="12,0,0,0" />
                                    </StackPanel>
                                    <toolkit1:ContextMenuService.ContextMenu>
                                        <toolkit1:ContextMenu Name="MyContextMenu">
                                            <toolkit1:MenuItem Header="delete measure" Click="DeleteItem_Click" CommandParameter="{Binding Id}" />
                                        </toolkit1:ContextMenu>
                                    </toolkit1:ContextMenuService.ContextMenu>
                                </Grid>
                            </DataTemplate>
                        </ListBox.ItemTemplate>
                    </ListBox>
                </Grid>-->
                
                <!-- VERSIONE 1.5 Raggruppate le misurazioni per mesi -->
                <Grid x:Name="MeasurementGrid">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="30" />
                        <RowDefinition />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition />                        
                    </Grid.ColumnDefinitions>
                    <TextBlock Text="Measures organized by months" Grid.Row="0" Grid.Column="0" TextAlignment="Center" Style="{StaticResource PhoneTextAccentStyle}" />
                    <ListBox x:Name="MeasurementListBox" Grid.Row="1" Grid.Column="0" toolkit1:TiltEffect.IsTiltEnabled="True" Margin="0,10,0,10" ItemsSource="{Binding MonthViewModel}" SelectionChanged="MeasurementListBox_SelectionChanged">
                        <ListBox.ItemContainerStyle>
                            <Style TargetType="ListBoxItem">
                                <Setter Property="Padding" Value="10" />
                                <!--<Setter Property="Margin" Value="0"/>-->                                
                            </Style>
                        </ListBox.ItemContainerStyle>
                        <ListBox.ItemTemplate>
                            <DataTemplate>
                                <Grid>
                                    <Grid.RowDefinitions>
                                        <RowDefinition />
                                    </Grid.RowDefinitions>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="340" />
                                        <ColumnDefinition Width="*" />
                                    </Grid.ColumnDefinitions>
                                    <TextBlock Text="{Binding MonthYear}" Grid.Row="0" Grid.Column="0" TextAlignment="Left" TextWrapping="NoWrap" Margin="12,0,0,0" Style="{StaticResource PhoneTextExtraLargeStyle}"/>
                                    <TextBlock Text="{Binding Count}" Grid.Row="0" Grid.Column="1" TextAlignment="Right" TextWrapping="NoWrap" Margin="12,0,0,0" Style="{StaticResource PhoneTextExtraLargeStyle}"/>
                                    <toolkit1:ContextMenuService.ContextMenu>
                                        <toolkit1:ContextMenu Name="MyContextMenu">
                                            <toolkit1:MenuItem Header="send email" Click="SendEmail_Click" CommandParameter="{Binding Key}" />
                                        </toolkit1:ContextMenu>
                                    </toolkit1:ContextMenuService.ContextMenu>
                                </Grid>                                                              
                            </DataTemplate>
                        </ListBox.ItemTemplate>
                    </ListBox>
                </Grid>

            </controls:PivotItem>

            <!--Pivot item three-->
            <!--<controls:PivotItem Header="graph">
            </controls:PivotItem>-->

            <controls:PivotItem Header="settings">
                <StackPanel>
                    <TextBlock Text="Write email address where you wanna send the results" TextWrapping="Wrap" Style="{StaticResource PhoneTextAccentStyle}" />
                    <TextBox x:Name="txtEmail" Text="{Binding Source={StaticResource appSettings}, Path=appSettings.EmailSetting, Mode=OneWay}">
                        <TextBox.InputScope>
                            <InputScope>
                                <InputScopeName NameValue="EmailNameOrAddress"></InputScopeName>
                            </InputScope>
                        </TextBox.InputScope>
                    </TextBox>
                    <Button x:Name="btnEmail" Content="Save" Click="btnEmail_Click"></Button>
                </StackPanel>
            </controls:PivotItem>

            <controls:PivotItem Header="privacy">
                <TextBlock Text="All data stored within the application are strictly confidential and will not be divulged or shared." TextWrapping="Wrap" /> 
            </controls:PivotItem>

            <controls:PivotItem Header="about">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="200" />
                        <RowDefinition Height="40" />
                        <RowDefinition Height="40" />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition />                        
                    </Grid.ColumnDefinitions>
                    <Button x:Name="AboutMe" Grid.Row="0" Grid.Column="0" Height="150" Margin="0" Padding="0" Click="AboutMe_Click">
                        <Button.Background>
                            <ImageBrush ImageSource="Images/LogoAppWP7.png"></ImageBrush>
                        </Button.Background>
                    </Button>
                    <TextBlock Grid.Row="1" Grid.Column="0" Text="Pressure Diary 1.5.0" TextWrapping="Wrap" HorizontalAlignment="Center" FontSize="24" FontWeight="Bold" />
                    <TextBlock Grid.Row="2" Grid.Column="0" Text="Developed By A4cc0st4" TextWrapping="Wrap" HorizontalAlignment="Center"></TextBlock>
                </Grid>
                
                
            </controls:PivotItem>
        </controls:Pivot>
        <Grid.Background>
            <ImageBrush ImageSource="/PressureDiary;component/Images/background.jpg" Opacity="0.5" />
        </Grid.Background>
    </Grid>

    <!--Sample code showing usage of ApplicationBar-->
    <!--<phone:PhoneApplicationPage.ApplicationBar>
        <shell:ApplicationBar IsVisible="True" IsMenuEnabled="True">
            <shell:ApplicationBarIconButton IconUri="/Images/appbar_button1.png" Text="Button 1"/>
            <shell:ApplicationBarIconButton IconUri="/Images/appbar_button2.png" Text="Button 2"/>
            <shell:ApplicationBar.MenuItems>
                <shell:ApplicationBarMenuItem Text="MenuItem 1"/>
                <shell:ApplicationBarMenuItem Text="MenuItem 2"/>
            </shell:ApplicationBar.MenuItems>
        </shell:ApplicationBar>
    </phone:PhoneApplicationPage.ApplicationBar>-->

</phone:PhoneApplicationPage>